/**
 * @file
 * @brief source of (module)
 * @details
 *  
 * @author buaa.byl
 * @date 2012-02-14 created
 */

/* ************************************************************************* */
/*              include files                                                */
/* ************************************************************************* */
#define _CRTDBG_MAP_ALLOC

#include <stdio.h>
#include <stdlib.h>

#ifdef _MSC_VER
#include <windows.h>
#include <crtdbg.h>
#endif

#include "getopt_win32.h"

/* ************************************************************************* */
/*              declare of file-based type or struct                         */
/* ************************************************************************* */


/* ************************************************************************* */
/*              define of file-based variable                                */
/* ************************************************************************* */


/* ************************************************************************* */
/*              declare of file-based interface                              */
/* ************************************************************************* */


/* ************************************************************************* */
/*              define of module interface                                   */
/* ************************************************************************* */


/* ************************************************************************* */
/*              define of file-based interface                               */
/* ************************************************************************* */



/**
 * @brief program entry.
 * @details
 *        The first function call by systm.
 * @param[in]   argc number of command line arguments.
 * @param[in]   argv array of command line arguments.
 * @return      any int value.
 */
int main(int argc, const char* argv[])
{
    //Adding source below.
    const char* format = "hx:y:d";
    GETOPT_INFO* parsed_args = NULL;
    int i = 0;

#ifdef _MSC_VER
    //Enable crt dbg
    _CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
    _CrtSetReportMode(_CRT_WARN, _CRTDBG_MODE_FILE);
    _CrtSetReportMode(_CRT_ERROR, _CRTDBG_MODE_FILE);
    _CrtSetReportMode(_CRT_ASSERT, _CRTDBG_MODE_FILE);
    _CrtSetReportFile(_CRT_WARN, GetStdHandle(STD_ERROR_HANDLE));
    _CrtSetReportFile(_CRT_ERROR, GetStdHandle(STD_ERROR_HANDLE));
    _CrtSetReportFile(_CRT_ASSERT, GetStdHandle(STD_ERROR_HANDLE));
#endif


    parsed_args = getopt_win32(argc, argv, format);
    if (parsed_args != NULL) {
        //Walk
        for (i = 0;i < parsed_args->nr_opts;i++) {
            if (parsed_args->opts[i].arg == NULL) {
                printf("-%c\n", parsed_args->opts[i].opt);
            } else {
                printf("-%c %s\n", parsed_args->opts[i].opt,
                        parsed_args->opts[i].arg);
            }
        }

        for (i = 0;i < parsed_args->nr_args;i++) {
            printf("%s\n", parsed_args->args[i]);
        }

        getopt_free(parsed_args);
    }

    return 0;
}
